/*
 * GradientPaint.java  0.4.0 / Oct 24, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
package com.cute4j.swing.graphics;

/**
 * Gradient Paint.
 *
 * @author Slobodan Vrkacevic
 * @version 0.4.0
 */
public final class GradientPaint extends Paint {

// Private Fields. -------------------------------------------------------------

  private final Point p1;
  private final Point p2;
  private final Color c1;
  private final Color c2;
  private final boolean cyclic;

// Public Constructors. --------------------------------------------------------

  /**
   * Constructs new GradientPaint object.
   *
   * @param x1 the x coordinate of the first anchor point
   * @param y1 the y coordinate of the first anchor point
   * @param c1 the color of the first anchor point
   * @param x2 the x coordinate of the second anchor point
   * @param y2 the y coordinate of the second anchor point
   * @param c2 the color of the second anchor point
   * @param cyclic if <tt>true</tt> the gradient is cyclic
   */
  public GradientPaint(int x1, int y1, Color c1, int x2, int y2, Color c2,
                       boolean cyclic) {
    if (c1 == null) {
      throw new IllegalArgumentException("Null c1 color");
    }
    if (c2 == null) {
      throw new IllegalArgumentException("Null c2 color");
    }
    p1 = new Point(x1, y1);
    p2 = new Point(x2, y2);
    this.c1 = c1;
    this.c2 = c2;
    this.cyclic = cyclic;
  }

  /**
   * Constructs new GradientPaint object.
   *
   * @param p1 the first anchor point
   * @param c1 the color of the first anchor point
   * @param p2 the second anchor point
   * @param c2 the color of the second anchor point
   * @param cyclic if <tt>true</tt> the gradient is cyclic
   */
  public GradientPaint(Point p1, Color c1, Point p2, Color c2, boolean cyclic) {
    this(p1.getX(), p1.getY(), c1, p2.getX(), p2.getY(), c2, cyclic);
  }

  /**
   * Constructs new GradientPaint object.
   *
   * @param x1 the x coordinate of the first anchor point
   * @param y1 the y coordinate of the first anchor point
   * @param c1 the color of the first anchor point
   * @param x2 the x coordinate of the second anchor point
   * @param y2 the y coordinate of the second anchor point
   * @param c2 the color of the second anchor point
   */
  public GradientPaint(int x1, int y1, Color c1, int x2, int y2, Color c2) {
    this(x1, y1, c1, x2, y2, c2, false);
  }

  /**
   * Constructs new GradientPaint object.
   *
   * @param p1 the first anchor point
   * @param c1 the color of the first anchor point
   * @param p2 the second anchor point
   * @param c2 the color of the second anchor point
   */
  public GradientPaint(Point p1, Color c1, Point p2, Color c2) {
    this(p1.getX(), p1.getY(), c1, p2.getX(), p2.getY(), c2, false);
  }

// Public Methods. -------------------------------------------------------------

  /**
   * Returns the x coordinate of the first anchor point.
   *
   * @return the x coordinate of the first anchor point
   */
  public int getX1() {
    return p1.getX();
  }

  /**
   * Returns the y coordinate of the first anchor point.
   *
   * @return the y coordinate of the first anchor point
   */
  public int getY1() {
    return p1.getY();
  }

  /**
   * Returns the first anchor point.
   *
   * @return the first anchor point
   */
  public Point getPoint1() {
    return p1;
  }

  /**
   * Returns the x coordinate of the second anchor point.
   *
   * @return the x coordinate of the second anchor point
   */
  public int getX2() {
    return p2.getX();
  }

  /**
   * Returns the y coordinate of the second anchor point.
   *
   * @return the y coordinate of the second anchor point
   */
  public int getY2() {
    return p2.getY();
  }

  /**
   * Returns the second anchor point.
   *
   * @return the second anchor point
   */
  public Point getPoint2() {
    return p2;
  }

  /**
   * Returns the first anchor color.
   *
   * @return the first anchor color
   */
  public Color getColor1() {
    return c1;
  }

  /**
   * Returns the second anchor color.
   *
   * @return the second anchor color
   */
  public Color getColor2() {
    return c2;
  }

  /**
   * Returns <tt>true</tt> if the GradientPaint is cyclic; otherwise
   *         <tt>false</tt>.
   *
   * @return <tt>true</tt> if the GradientPaint is cyclic; otherwise
   *         <tt>false</tt>
   */
  public boolean isCyclic() {
    return cyclic;
  }

}
